package hjslm.Controller.Background;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import hjslm.Bean.PictureBean;
import hjslm.Common.Impl.CommonFunImpl;
import hjslm.Service.IPictureService;
import framework.base.common.Pager;
import framework.base.controller.BaseController;

@Controller
@RequestMapping("/b_picture")
public class PictureController extends BaseController {

	/**
	 * 教师图片控制层
	 */
	private static final long serialVersionUID = 1L;
	
	@Autowired
	IPictureService pictureService;

	@Override
	public void setLogger() {
	}
	
	@RequestMapping("/index")
	public ModelAndView index(Pager<PictureBean> pager){
		ModelAndView modelAndView = new ModelAndView("background/advertisement/index");
		pager = pictureService.selectPage(null, pager);
		modelAndView.addObject("pager", pager);
		return modelAndView;
	}
	
	@RequestMapping("/add")
	public ModelAndView add(String teaid){
		ModelAndView modelAndView = new ModelAndView("background/teacher/zhengshu/add");
		modelAndView.addObject("teaid", teaid);
		return modelAndView;
	}
	
	@RequestMapping("/edit")
	public ModelAndView edit(PictureBean bean){
		ModelAndView modelAndView = new ModelAndView("background/teacher/zhengshu/edit");
		bean = pictureService.selectOne(bean);
		modelAndView.addObject("bean", bean);
		return modelAndView;
	}
	
	@RequestMapping("/insert")
	public void insert(PictureBean bean,HttpServletResponse response){
		bean.setId(CommonFunImpl.uuid("P"));
		bean.setInserttime(CommonFunImpl.currentTime(1));
		bean.setPictype("1");
		int retVal = pictureService.insert(bean);
		// 返回值
		try {
			PrintWriter out = response.getWriter();
			out.print(retVal);
			out.close();
		} catch (IOException e) {
			e.printStackTrace();// 打印异常
		}
	}
	
	@RequestMapping("/update")
	public void update(PictureBean bean,HttpServletResponse response){
		bean.setInserttime(CommonFunImpl.currentTime(1));
		int retVal = pictureService.update(bean);
		// 返回值
		try {
			PrintWriter out = response.getWriter();
			System.out.print(retVal);
			out.print(retVal);
			out.close();
		} catch (IOException e) {
			e.printStackTrace();// 打印异常
		}
	}
	
	@RequestMapping("/delete")
	public void Delete(PictureBean bean, HttpServletResponse response) {
		response.setCharacterEncoding("UTF-8");
		int ret = pictureService.delete(bean);
		try {
			PrintWriter out = response.getWriter();
			out.print(ret);
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
